package com.bwie.controller;

import com.bwie.pojo.Ball;
import com.bwie.service.BallService;
import com.bwie.utils.OSSFileUtil;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author lenovo
 */
@RestController
@RequestMapping("/ball")
public class BallController {
    @Autowired
    private BallService ballService;

    @Autowired
    private OSSFileUtil ossFileUtil;

    @PostMapping("/list")
    public R list(){
        List<Ball> ballList = ballService.ballList();
        return R.OK(ballList);
    }

    @PostMapping("/uploadFile")
    public R uploadFile(MultipartFile file) throws IOException {
        String s = ossFileUtil.uploadFile(file);
        return R.OK(s);
    }
    @PostMapping("/addBall")
    public R addBall(@RequestBody Ball ball){
        return ballService.addBall(ball);
    }
}
